package com.hyy.lotterysystem.dao.mapper;

import com.hyy.lotterysystem.dao.dataobject.FailedMessageDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 失败消息Mapper接口
 */
@Mapper
@Repository
public interface FailedMessageMapper {
    
    /**
     * 插入失败消息记录
     * 
     * @param failedMessage 失败消息对象
     * @return 影响的行数
     */
    @Insert("INSERT INTO failed_message(message_content) VALUES(#{messageContent})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(FailedMessageDO failedMessage);
    
    /**
     * 根据ID查询失败消息
     * 
     * @param id 消息ID
     * @return 失败消息对象
     */
    @Select("SELECT id, message_content as messageContent, create_time as gmtCreate FROM failed_message WHERE id = #{id}")
    FailedMessageDO selectById(Long id);
    
    /**
     * 查询最近的失败消息列表
     * 
     * @param limit 限制数量
     * @return 失败消息列表
     */
    @Select("SELECT id, message_content as messageContent, create_time as gmtCreate FROM failed_message ORDER BY create_time DESC LIMIT #{limit}")
    List<FailedMessageDO> selectRecentMessages(int limit);
} 